package server;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class HandlingClients extends Thread
{
	String[] usernames = Init.loadNames();
    Socket client;
    HandlingClients(Socket client) 
    {
        this.client = client;
    }
    public void run() 
    {
    	PrintWriter outclient = null;
    	BufferedReader inclient = null;
    	try {
			outclient = new PrintWriter(client.getOutputStream(), true);
			inclient = new BufferedReader(new InputStreamReader(client.getInputStream()));
		} catch (IOException e) {
			System.out.println("Accept failed: 31415");
			System.exit(-1);
		}
    	DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
    	Date date = new Date();
    	try
		{
			System.out.println("Accepting connection for " + inclient.readLine() + " at " + dateFormat.format(date));
		}
		catch (IOException e)
		{
			System.out.println("Impossible Error at printing the reported IP Address");
			try
			{
				client.close();
			}
			catch (IOException e1) {}
			System.exit(-1);
		}
    	String username = null;
    	try
		{
			username = inclient.readLine();
		}
		catch (IOException e)
		{
			System.out.println("Error at reading the username!");
			try
			{
				client.close();
			}
			catch (IOException e1) {}
			System.exit(-1);
		}
    	int usernamePos = arraySearch()
    }
}
